import React from 'react'
import { Item, Submit, Reset, Layout, SchemaType } from '@amazebird/antd-schema-form'
import SmartForm from './SmartForm'

const schema: SchemaType = {
  name: {
    label: '姓名',
    component: 'Input',
    max: 5
  },
  age: {
    label: '年龄',
    component: 'InputNumber'
  },
  nation: {
    label: '民族',
    component: 'Select',
    options: [{ label: '汉族', value: 1 }, { label: '满族', value: 2 }]
  },
  sex: {
    label: '性别',
    component: 'Radio',
    options: [{ label: '男', value: 1 }, { label: '女', value: 0 }]
  },
  interest: {
    label: '兴趣',
    component: 'Checkbox',
    options: [{ label: '电影', value: 'film' }, { label: '音乐', value: 'music' }, { label: '旅游', value: 'tour' }]
  },
  birthday: {
    label: '出生日期',
    component: 'DatePicker'
  },
  introduce: {
    label: '自我介绍',
    component: 'Input.TextArea',
    props: {
      maxLength: 300
    }
  }
}

const defaultValues = {
  sex: 1,
  nation: 1
}

const initialValues = {
  name: 'jony',
  age: 23,
  nation: 2
}


function promiseFn(){
  return 'test'
}

async function call(){
  const result = await promiseFn()
  console.info(result)
}

call()


function Base() {
  function onFinish(data) {
    console.info(data)
  }

  return (
    <SmartForm schema={schema} initialValues={initialValues} defaultValues={defaultValues}>
      <Item field="name" />
      <Item field="age" />
      <Item field="nation" />
      <Item field="sex" />
      <Item field="interest" />
      <Item field="birthday" />
      <Item field="introduce" />
      <Layout offset={8}>
        <Submit onFinish={onFinish} />
        <Reset />
      </Layout>
    </SmartForm>
  )
}

export default Base
